using System.Collections.Generic;
using Serilog;
using UnityEngine;
using Sirenix.OdinInspector;

namespace MoonFramework.Template
{
    /// <summary>
    /// 所有游戏中（非框架）基类，游戏运行中只有一个
    /// 包含所有的配置文件
    /// </summary>
    [CreateAssetMenu(fileName = "ConfigSetting", menuName = "MoonFramework/ConfigSetting")]
    public class ConfigSetting : BaseConfig
    {
        /// <summary>
        /// 所有配置的集合
        /// </summary>
        [DictionaryDrawerSettings(KeyLabel = "类型", ValueLabel = "列表")]
        public Dictionary<string, Dictionary<string, BaseConfig>> configs = new();

        public Dictionary<string, BaseConfig> GetConfigs(string configTypeName)
        {
            if(!configs.TryGetValue(configTypeName, out var Dic))
            {
                Log.Error("Config Error  : 配置设置中不存在这个类型");
            }
            return Dic;
        }

        /// <summary>
        /// 获取配置
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="configTypeName"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public T GetConfig<T>(string configTypeName, string id) where T : BaseConfig
        {
            if (!configs.TryGetValue(configTypeName, out var keys))
            {
                Log.Error("Config Error  : 不存在这个类型");
                return null;
            }
            if (!keys.TryGetValue(id, out var config))
            {
                Log.Error("ID Error: 不存在这个ID");
                return null;
            }
            return config as T;
        }
    }
}